#include <vector>
#include <cstring>
using namespace std;
/*
 * @lc app=leetcode.cn id=36 lang=cpp
 *
 * [36] 有效的数独
 */

// @lc code=start
class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        int rows[9][9], columns[9][9], boxes[3][3][9];
        memset(rows, 0, sizeof rows);
        memset(columns, 0, sizeof rows);
        memset(boxes, 0, sizeof boxes);
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') continue;
                int index = board[i][j] - '0' - 1;
                rows[i][index]++; columns[j][index]++;
                boxes[i / 3][j / 3][index]++;
                if (rows[i][index] > 1 || columns[j][index] > 1 || boxes[i / 3][j / 3][index] > 1) return false;
            }
        }
        return true;
    }
};
// @lc code=end

